import moment from 'moment'
const host = 'http://api.youjiaoyun.net/weixin.asmx/'
const timeFormat = 'YYYY-MM-DD HH:mm:ss'

export default {
  getCityList (provinceId) {
    return window.$.ajax({
      url: `${host}GetCityList?jsoncallback=?`,
      dataType: 'jsonp',
      data: {
        ProvinceId: provinceId
      },
      async: true,
      jsonp: 'jsoncallback'
    })
  },
  // 身高体重
  // const avgData = {ProvinceId: idObj[0].ProvinceId, CityId: 0, DistrictId: 0, Gid: 0, StartDate: '2018-04-10 00:00:01', EndDate: '2018-04-10 23:59:59'}
  getAvgBodyCheckResult (opt) {
    const now = moment()
    return window.$.ajax({
      url: `${host}GetAvgBodyCheckResult?jsoncallback=?`,
      dataType: 'jsonp',
      data: {
        ...opt,
        StartDate: moment(now).startOf('month').format(timeFormat),
        EndDate: moment(now).endOf('month').format(timeFormat),
        IsMonth: false
      },
      async: true,
      jsonp: 'jsoncallback'
    })
  },
  // BMI
  getBodyCheckResultList (opt) {
    const now = moment()
    return window.$.ajax({
      url: `${host}GetBodyCheckResultList?jsoncallback=?`,
      dataType: 'jsonp',
      data: {
        ...opt,
        StartDate: moment(now).startOf('month').format(timeFormat),
        EndDate: moment(now).endOf('month').format(timeFormat),
        IsMonth: false
      },
      async: true,
      jsonp: 'jsoncallback'
    })
  },
  getGardenAvgDataList (gardenId) {
    const now = moment()
    return window.$.ajax({
      url: `${host}GetGardenAvgDataList?jsoncallback=?`,
      dataType: 'jsonp',
      data: {
        gid: gardenId,
        sdate: moment(now).startOf('month').format('YYYY-MM-DD'),
        edate: moment(now).format('YYYY-MM-DD')
      },
      async: true,
      jsonp: 'jsoncallback'
    })
  }
}
